/* -----------------------------------------------------------------------
 * Christine Hayes
 * Using provided template testUpdateCoins.c
 * This test is for the numHandCards() function
 * This makes sure that the function returns the proper number for a known
 * hand.
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

int main() {
    int i;
    int seed = 1000;
    int numPlayer = 2;

    int p, r, handCount;

    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    // arrays of all coppers, silvers, and golds
	// Also, one hand with all smithy cards
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
	int none[MAX_HAND];
	
	int cardNum;
	
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
		none[i] = smithy;
    }

    printf ("TESTING numHandCards():\n");
	p = 0;
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {
#if (NOISY_TEST == 1)
                printf("Test player %d with %d cards.\n", p, handCount);
#endif
                memset(&G, 23, sizeof(struct gameState));   // clear the game state
                r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
                G.handCount[p] = handCount;                 // set the number of cards on hand
				
                memcpy(G.hand[p], coppers, sizeof(int) * handCount); // set all the cards to copper
                cardNum = numHandCards(&G);
#if (NOISY_TEST == 1)
                printf("cardNum = %d, expected = %d\n", cardNum, handCount);
#endif
                assert(cardNum == handCount); // check if cardNum coins is correct

                memcpy(G.hand[p], silvers, sizeof(int) * handCount); // set all the cards to silver
                cardNum = numHandCards(&G);
#if (NOISY_TEST == 1)
                printf("cardNum = %d, expected = %d\n", cardNum, handCount);
#endif
                assert(cardNum == handCount); // check if cardNum is correct

                memcpy(G.hand[p], golds, sizeof(int) * handCount); // set all the cards to gold
                cardNum = numHandCards(&G);
#if (NOISY_TEST == 1)
                printf("cardNum = %d, expected = %d\n", cardNum, handCount);
#endif
                assert(cardNum == handCount); // check if cardNum is correct
				
				/* Here is the test I added: */				
				memcpy(G.hand[p], none, sizeof(int) * handCount); // set all the cards non-treasure
                cardNum = numHandCards(&G);
#if (NOISY_TEST == 1)
                printf("cardNum = %d, expected = %d\n", cardNum, handCount);
#endif
                assert(cardNum == handCount); // check if cardNum is correct
            }


    printf("All tests passed!\n");

    return 0;
}